﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QunYing.Web.market
{
    public partial class scoregoods : System.Web.UI.Page
    {
        private string DealerID = "";
        protected override void OnInit(EventArgs e)
        {
            if (Session["userInfo"] == null)
            {
                Response.Redirect("~/Login.aspx");
            }
            else
            {
                DealerID = ((ArrayList)Session["userInfo"])[4].ToString();
            }
            base.OnLoad(e);

        }
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Repeater rp = ((Repeater)Master.FindControl("NavRepeater"));
                rp.DataSource = NavData();
                rp.DataBind();
            }
        }
        /// <summary>
        /// 快捷导航数据
        /// </summary>
        private DataTable NavData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name");
            dt.Columns.Add("url");
            DataTable dtNode = null;
            if (Request["category"] != null)
            {
                dtNode = new BLL.Category().GetParentCategory(Request["category"]);

                if (dtNode.Rows.Count > 0)
                {
                    dt.Rows.Add("积分兑换", "scoregoods.aspx");
                    for (int i = 0; i < dtNode.Rows.Count - 1; i++)
                    {
                        dt.Rows.Add(dtNode.Rows[i]["类别名称"].ToString(), "scoregoods.aspx?category=" + dtNode.Rows[i]["类别ID"]);
                    }
                    dt.Rows.Add(dtNode.Rows[dtNode.Rows.Count - 1]["类别名称"].ToString(), "");
                }
                else
                {
                    dt.Rows.Add("积分兑换", "");
                }
            }
            else
            {
                dt.Rows.Add("积分兑换", "");
            }
            return dt;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GoodsBind(ScoreRepeater, 0, "是否兑换", Request["category"] != null ? int.Parse(Request["category"]) : 0);
            }
        }

        /// <summary>
        /// 绑定商品
        /// </summary>
        private void GoodsBind(Repeater rp, int top, string type, int catagory)
        {
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = new BLL.GoodsInfo().GetGoodsInfo(top, type, catagory, DealerID).DefaultView;

            //pds.AllowCustomPaging = true;
            pds.AllowPaging = true;
            //pds.AllowServerPaging = true;
            pds.PageSize = 20;

            int currentPage = Convert.ToInt32(Request["page"]);

            //设当前页
            pds.CurrentPageIndex = currentPage;

            //设几个超链接
            if (!pds.IsFirstPage)
            {
                lnkUp.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage - 1);
                lnkUp2.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage - 1);
            }

            if (!pds.IsLastPage)
            {
                lnkDown.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage + 1);
                lnkDown2.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage + 1);
            }


            lbl_info.Text = "第&nbsp;<span style='color:blue;'>" + (currentPage + 1) +
                "</span>&nbsp;页&nbsp;&nbsp;共&nbsp;" + pds.PageCount + "&nbsp;页";
            lbl_info2.Text = "第&nbsp;<span style='color:blue;'>" + (currentPage + 1) +
                "</span>&nbsp;页&nbsp;&nbsp;共&nbsp;" + pds.PageCount + "&nbsp;页";

            rp.DataSource = pds;
            rp.DataBind();
            //DataTable dt = new BLL.GoodsInfo().GetGoodsInfo(top, type, catagory, DealerID);
            //rp.DataSource = dt;
            //rp.DataBind();
        }
    }
}
